/**
 * 
 */
package com.sample.service.information;

import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.xml.bind.JAXBException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sample.core.Project;

/**
 *
 */
public class InformationImpl implements Information {

	private static final String PROJECT_XML = "project.xml";
	private static Logger logger = LoggerFactory.getLogger(InformationImpl.class);

	/**
	 * 
	 */
	public InformationImpl() {
	}

	public com.sample.core.Project getProject() throws WebApplicationException {
		try {
			final Project readProject = Project.read(InformationImpl.class.getResourceAsStream(PROJECT_XML));
			if(logger.isInfoEnabled()){
				logger.info("Project {}", readProject);
			}
			return readProject;
		} catch (JAXBException e) {
			logger.error("getVersion", e);
			throw new WebApplicationException(e);
		} 
	}

	public List<Project> getProjects() throws WebApplicationException {
		try {
			final Project cxfsansspring = Project.read(InformationImpl.class.getResourceAsStream(PROJECT_XML));
			final Project cxfsansspringCore = Project.read();
			List<Project> allProject = com.google.common.collect.Lists.newArrayList(cxfsansspring, cxfsansspringCore);
			
			if(logger.isInfoEnabled()){
				logger.info("Project {}", allProject);
			}
			return allProject;
		} catch (JAXBException e) {
			logger.error("getAll", e);
			throw new WebApplicationException(e);
		} 
	}

}
